/**
*┌──────────────────────────────────────────────────────────────┐
*│　描    述：User_login_log接口实现                                                    
*│　作    者：NetCoreCMS                                            
*│　版    本：1.0    模板代码自动生成                                                
*│　创建时间：2019-12-25 10:52:46                             
*└──────────────────────────────────────────────────────────────┘
*┌──────────────────────────────────────────────────────────────┐
*│　命名空间： NetCoreCMS.Repository.SqlServer                                  
*│　类    名： User_login_logRepository                                      
*└──────────────────────────────────────────────────────────────┘
*/
using NetCoreCMS.DbHelper;
using NetCoreCMS.IRepository;
using NetCoreCMS.Models;
using Dapper;
using Microsoft.Extensions.Options;
using System;
using System.Threading.Tasks;

namespace NetCoreCMS.Repository.SqlServer
{
    public class User_login_logRepository:BaseRepository<User_login_log,Int32>, IUser_login_logRepository
    {
        public User_login_logRepository(IOptionsSnapshot<DbOption> options)
        {
            _dbOption =options.Get("NetCoreCMS");
            if (_dbOption == null)
            {
                throw new ArgumentNullException(nameof(DbOption));
            }
            //_dbConnection = ConnectionFactory.CreateConnection(_dbOption.DbType, _dbOption.ConnectionString);
        }
        /// <summary>
        /// 同一天内是否有登录过
        /// </summary>
        public bool ExistsDay(string username)
        {
            var model = Get("select * from ["+nameof(User_login_log)+"] where  user_name=@user_name and DATEDIFF(d,login_time,getdate())=0", new { user_name = username });
            return model!=null?true:false;
        }

        /// <summary>
        /// 根据用户名取得最后登录的MODEL
        /// </summary>
        public Models.User_login_log GetLastModel(string user_name)
        {
            var model = Get("select * from [" + nameof(User_login_log) + "] where user_name=@user_name order by id desc", new { user_name = user_name });
            return model;
        }
    }
}